﻿CREATE PROCEDURE [dbo].[yaf_user_activity_rank](
                @StartDate AS DATETIME)
AS
    BEGIN
        SELECT   TOP 3 ID,
                       Name,
                       NumOfPosts
        FROM     yaf_User u
                 INNER JOIN (SELECT   m.UserID         AS ID,
                                      COUNT(m.UserID)  AS NumOfPosts
                             FROM     yaf_Message m
                             WHERE    m.Posted >= @StartDate
                             GROUP BY m.UserID) AS counter
                   ON u.UserID = counter.ID
        ORDER BY NumOfPosts DESC
    END


